<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script type="text/javascript">

        // 3.要求输入一串低于10位的数字，输出对应的中文大写:
        //替换
        var num = prompt('请输入一个数字');
        var up = '零一二三四五六七八九';
        var str = num.toString();
        var str2 = '';
        for (let index = 0; index < str.length; index++) {
            for (let index2 = 0; index2 < up.length; index2++) {
                if (str[index] == index2) {
                    str2 += up[index2];
                }
            }
        }




        //反转
        var temp = str2.split('');
        str2 = (temp.reverse()).join('');




        //拼接单位
        var final = '';

        const unit = ['十','百','千','万','万十','万百','万千','亿','亿十','亿百','亿千']

        //去零
        var zero = '一';
        if (str2[0]=='零') {
            zero = '零'
        }


        for (let index = 0; index < str2.length; index++) {
            if (index == str2.length-1) {
                final += str2.slice(index)
            }else{
                if (str2[index+1]=='零') {
                    if (zero!='零') {
                        final += str2.slice(index,index+1)
                    }
                    zero = str2[index+1]
                }else{
                    final += str2.slice(index,index+1) + unit[index]
                    zero = '一';
                }
            }
        }

        //回转
        temp = final.split('');
        var count0 = 0;
        final = (temp.reverse()).join('');

        //去除尾数零
        if (final[final.length-1]=='零') {
            final = final.slice(0,final.length-1)
        }
        
        document.write(final);







































        // const arr = str2.split('');
        // var str3 = (arr.reverse()).join('');
        // const arr1 = [str3]






        // var final = str2;
        // var x = '十百千万亿';
        // // const y = ['十万','百万','千万']
        // // // for (let index = str2.length-2; index >= 0; index--) {
        // // //     for (let index2 = 0; index2 < x.length; index2++) {
        // // //         final = str2.slice(0,index) + x[index2] + str2.slice(index);
        // // //     }    
        // // // }
        
        // // final = str2.slice(0,1) + x[0] + str2.slice(1);

        // for (let index = 0; index < str3.length; index++) {
        //     arr1[index+1] = arr1[index][index+1].slice(0,index+1)
        //     + x[index] + arr1[index][index+1].slice(index+1);
        // }
        
        // document.write(arr1);








        // document.write(final);
        // 例： input: 10001  --> 一万零一     ；   input:  10,000,000  -->  一千万
    </script>
</body>

</html>